package com.motorhome.h5.dao.impl;

import com.motorhome.base.dao.impl.BaseDaoImpl;
import com.motorhome.h5.dao.LoginDao;
import com.motorhome.h5.domain.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

/**
 * @author: John
 */
@Repository
public class LoginDaoImpl extends BaseDaoImpl implements LoginDao {

    @Override
    public int insertUser(String phone, String openId) {
        return update("insert into uc_user(phone,user_name,card_id,open_id) values(?,?,?,?)", phone, phone, phone, openId);
    }

    @Override
    public int updateUser(Long userId, String md5Pass, String realName) {
        return update("update uc_user set login_pass=?,user_name=? where id = ?", md5Pass, realName, userId);
    }

    @Override
    public int insertOpenUser(String phone, String trueName, String cardId, String openId) {
        return update("insert into uc_user(phone,user_name,card_id,open_id) values(?,?,?,?)", phone, trueName, cardId, openId);
    }

    @Override
    public User getUserByOpenId(String openId) {
        return queryForObject("select id,phone,login_pass,user_name,card_id,open_id from uc_user where open_id = ?",
                new BeanPropertyRowMapper<>(User.class), openId);
    }

    @Override
    public int updateUserOpenId(Long userId, String openId) {
        return update("update uc_user set open_id=? where id = ?", openId, userId);
    }

}
